Skip to content

Commit

Permalink
Merge pull request #5 from evias/add-alias-transaction
Browse files Browse the repository at this point in the history
- Added AddressAliasTransaction + schema + buffer
- Added MosaicAliasTransaction + schema + buffer
  • Loading branch information
evias authored Feb 25, 2019
2 parents a2390dc + 89c2754 commit 659a2e7
Show file tree
Hide file tree
Showing 13 changed files with 1,496 additions and 0 deletions.
479 changes: 479 additions & 0 deletions src/buffers/AddressAliasTransactionBuffer.js

Large diffs are not rendered by default.

479 changes: 479 additions & 0 deletions src/buffers/MosaicAliasTransactionBuffer.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ export * from './crypto/sha3Hasher';
export * from './coders/convert';
export * from './coders/address';
export * from './coders/uint64';
export * from './transactions/AddressAliasTransaction';
export * from './transactions/AggregateTransaction';
export * from './transactions/CosignatureTransaction';
export * from './transactions/HashLockTransaction';
export * from './transactions/MosaicAliasTransaction';
export * from './transactions/MosaicCreationTransaction';
export * from './transactions/MosaicSupplyChangeTransaction';
export * from './transactions/MultisigModificationTransaction';
Expand Down
12 changes: 12 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ import CosignatureTransaction from './transactions/CosignatureTransaction';
import AggregateTransaction from './transactions/AggregateTransaction';
import HashLockTransaction from './transactions/HashLockTransaction';
import deadline from './transactions/Deadline';
import AddressAliasTransaction from './transactions/AddressAliasTransaction';
import MosaicAliasTransaction from './transactions/MosaicAliasTransaction';
import MosaicCreationTransaction from './transactions/MosaicCreationTransaction';
import MosaicSupplyChangeTransaction from './transactions/MosaicSupplyChangeTransaction';
import MultisigModificationTransaction from './transactions/MultisigModificationTransaction';
Expand Down Expand Up @@ -405,6 +407,16 @@ export {
*/
HashLockTransaction,

/**
* @property {module:transactions/AddressAliasTransaction}
*/
AddressAliasTransaction,

/**
* @property {module:transactions/MosaicAliasTransaction}
*/
MosaicAliasTransaction,

/**
* @property {module:transactions/MosaicCreationTransaction}
*/
Expand Down
38 changes: 38 additions & 0 deletions src/schema/AddressAliasTransactionSchema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2019 NEM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { array, Schema, TypeSize, ubyte, uint, ushort } from './Schema';

/**
* @module schema/AddressAliasTransactionSchema
*/

/**
* Address alias transaction schema
* @const {module:schema/Schema}
*/
export default new Schema([
uint('size'),
array('signature'),
array('signer'),
ushort('version'),
ushort('type'),
array('fee', TypeSize.INT),
array('deadline', TypeSize.INT),
ubyte('actionType'),
array('namespaceId', TypeSize.INT),
array('address', TypeSize.BYTE)
]);
38 changes: 38 additions & 0 deletions src/schema/MosaicAliasTransactionSchema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2019 NEM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { array, Schema, TypeSize, ubyte, uint, ushort } from './Schema';

/**
* @module schema/MosaicAliasTransactionSchema
*/

/**
* Mosaic alias transaction schema
* @const {module:schema/Schema}
*/
export default new Schema([
uint('size'),
array('signature'),
array('signer'),
ushort('version'),
ushort('type'),
array('fee', TypeSize.INT),
array('deadline', TypeSize.INT),
ubyte('actionType'),
array('namespaceId', TypeSize.INT),
array('mosaicId', TypeSize.INT)
]);
42 changes: 42 additions & 0 deletions src/transactions/AddressAliasTransaction.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2019 NEM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {VerifiableTransaction} from "./VerifiableTransaction";

export declare class AddressAliasTransaction extends VerifiableTransaction {
}

export declare module AddressAliasTransaction {
class Builder {

addFee(fee): Builder;

addVersion(version): Builder;

addType(type): Builder;

addDeadline(deadline): Builder;

addActionType(direction): Builder;

addNamespaceId(namespaceId): Builder;

addAddress(address): Builder;

build(): AddressAliasTransaction;

}
}
115 changes: 115 additions & 0 deletions src/transactions/AddressAliasTransaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright 2019 NEM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import VerifiableTransaction from './VerifiableTransaction';
import AddressAliasTransactionSchema from '../schema/AddressAliasTransactionSchema';
import AddressAliasTransactionBufferPackage from '../buffers/AddressAliasTransactionBuffer';

const { AddressAliasTransactionBuffer } = AddressAliasTransactionBufferPackage.Buffers;

const { flatbuffers } = require('flatbuffers');
const addressEncoder = require('../coders/address').default;

/**
* @module transactions/AddressAliasTransaction
*/
export default class AddressAliasTransaction extends VerifiableTransaction {
static get Builder() {
class Builder {
constructor() {
this.fee = [0, 0];
this.version = 36865;
this.type = 0x424E;
}

addFee(fee) {
this.fee = fee;
return this;
}

addVersion(version) {
this.version = version;
return this;
}

addType(type) {
this.type = type;
return this;
}

addDeadline(deadline) {
this.deadline = deadline;
return this;
}

addActionType(actionType) {
this.actionType = actionType;
return this;
}

addNamespaceId(namespaceId) {
this.namespaceId = namespaceId;
return this;
}

addAddress(address) {
this.address = addressEncoder.stringToAddress(address);
return this;
}

build() {
const builder = new flatbuffers.Builder(1);

// Create vectors
const signatureVector = AddressAliasTransactionBuffer
.createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0));
const signerVector = AddressAliasTransactionBuffer
.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0));
const deadlineVector = AddressAliasTransactionBuffer
.createDeadlineVector(builder, this.deadline);
const feeVector = AddressAliasTransactionBuffer
.createFeeVector(builder, this.fee);
const namespaceIdVector = AddressAliasTransactionBuffer
.createNamespaceIdVector(builder, this.namespaceId);
const addressVector = AddressAliasTransactionBuffer
.createAddressVector(builder, this.address);


AddressAliasTransactionBuffer.startAddressAliasTransactionBuffer(builder);
AddressAliasTransactionBuffer.addSize(builder, 154);
AddressAliasTransactionBuffer.addSignature(builder, signatureVector);
AddressAliasTransactionBuffer.addSigner(builder, signerVector);
AddressAliasTransactionBuffer.addVersion(builder, this.version);
AddressAliasTransactionBuffer.addType(builder, this.type);
AddressAliasTransactionBuffer.addFee(builder, feeVector);
AddressAliasTransactionBuffer.addDeadline(builder, deadlineVector);
AddressAliasTransactionBuffer.addActionType(builder, this.actionType);
AddressAliasTransactionBuffer.addNamespaceId(builder, namespaceIdVector);
AddressAliasTransactionBuffer.addAddress(builder, addressVector);

// Calculate size
const codedMosaicChangeSupply = AddressAliasTransactionBuffer.endAddressAliasTransactionBuffer(builder);
builder.finish(codedMosaicChangeSupply);

const bytes = builder.asUint8Array();

return new AddressAliasTransaction(bytes, AddressAliasTransactionSchema);
}
}

return Builder;
}
}
42 changes: 42 additions & 0 deletions src/transactions/MosaicAliasTransaction.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2019 NEM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {VerifiableTransaction} from "./VerifiableTransaction";

export declare class MosaicAliasTransaction extends VerifiableTransaction {
}

export declare module MosaicAliasTransaction {
class Builder {

addFee(fee): Builder;

addVersion(version): Builder;

addType(type): Builder;

addDeadline(deadline): Builder;

addActionType(direction): Builder;

addNamespaceId(namespaceId): Builder;

addMosaicId(mosaicName): Builder;

build(): MosaicAliasTransaction;

}
}
Loading

0 comments on commit 659a2e7

Please sign in to comment.